<?php ob_start();?>
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include($root.'/standart/head.php');
include($root.'/standart/dateHeader.php');
include($root.'/standart/checkUser.php');
$db = connect();
$bgn_date = "";
$end_date = "";
$tmpDate = $_GET["begin_date"];
if($tmpDate <> ""){
	list($gun,$ay,$yil) = explode('/',$tmpDate);
	$bgn_date = $yil.'-'.$ay.'-'.$gun;
}
$tmpDate = $_GET["end_date"];
if($tmpDate <> ""){
	list($gun,$ay,$yil) = explode('/',$tmpDate);
	$end_date = $yil.'-'.$ay.'-'.$gun;
}
$invoiceNo = $_GET["invoice_no"];
$inventory = $_GET["inventory"];
$stmt ="SELECT MATERIALS.ID, INVENTORY_ID, INVENTORY_NAME, INVENTORY.UNIT AS UNIT_ID, MATERIALS.UNIT, QUANTITY, AMOUNT, TOTAL_AMOUNT, INVOICE_NO, INVOICE_DATE
		FROM MATERIALS, INVENTORY
		WHERE MATERIALS.INVENTORY_ID = INVENTORY.ID";
		if($bgn_date <> ""){
			$stmt = $stmt." AND INVOICE_DATE > '$bgn_date'";
		}
		if($end_date <> ""){
			$stmt = $stmt." AND INVOICE_DATE < '$end_date'";
		}
		if($invoiceNo <> ""){
			$stmt = $stmt." AND INVOICE_NO = '$invoiceNo'";
		}
		if($inventory <> ""){
			$stmt = $stmt." AND INVENTORY_ID = '$inventory'";
		}
$res = $db->query($stmt) or die($stmt."<br/><br/>".mysql_error());
	?>
	<table class="table table-striped table-bordered table-hover" id="dataTables-example">
		<thead>
        	<tr>
            	<th style="display: none;">ID</th>
                <th style="display: none;">Inventory ID</th>
                <th>Fatura No</th>
                <th>Fatura Tarihi</th>
                <th>Ürün Tipi</th>
                <th style="display: none;">Unit ID</th>
				<th>Adet</th>
                <th>Birim</th>
                <th>Birim Fiyat</th>
                <th>Toplam Fiyat</th>
            </tr>
		</thead>
        <tbody>
        <?php $odd = true; ?>
       	<?php while($row = $res->fetch_assoc()){?>
        	<tr class="<?php echo $odd ? "odd" : "even";?> " style="cursor: pointer;">
	            <td style="display: none;"><?php echo $row["ID"];?></td>
	            <td style="display: none;"><?php echo $row["INVENTORY_ID"];?></td>
	            <td><?php echo $row["INVOICE_NO"];?></td>
                <td><?php echo date("d/m/Y",strtotime($row["INVOICE_DATE"]));?></td>
                <td><?php echo $row["INVENTORY_NAME"];?></td>
                <td style="display: none;"><?php echo $row["UNIT_ID"];?></td>
                <td style="text-align: left;"><?php echo $row["QUANTITY"];?></td>
                <td><?php echo $row["UNIT"];?></td>
                <td style="text-align: left;"><?php echo $row["AMOUNT"];?></td>
                <td style="text-align: left;"><?php echo $row["TOTAL_AMOUNT"];?></td>
			</tr>
			<?php $odd = !$odd;?>
		<?php }?>
		<?php if(isset($_GET['report'])){?>
			<tfoot>
	            <tr>
	            	<td style="display: none;"></td>
	            	<td style="display: none;"></td>
	            	<td style="display: none;"></td>
	                <th colspan="6" style="text-align:right">Toplam:</th>
	                <th></th>
	            </tr>
	        </tfoot>
		<?php }?>
		</tbody>
     </table>
	<?php 
$res->close();
disconnect($db);
?>
<?php ob_end_flush(); ?>